package com.neu.question.form;

import com.neu.question.domain.UserInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TenantsForm {
    private String username;
    private String oldUsername;
    private String oldPhoneNum;
    private String password;
    private String phoneNum;
    private String startTime;
    private String stopTime;
    private String property;
    private String projectNum;

    public TenantsForm create(UserInfo userInfo, String property, String projectNum) throws ParseException {
        TenantsForm tenantsForm = new TenantsForm();
        tenantsForm.setUsername(userInfo.getUsername());
        tenantsForm.setOldUsername(userInfo.getUsername());
        tenantsForm.setPhoneNum(userInfo.getPhoneNum());
        tenantsForm.setOldPhoneNum(userInfo.getPhoneNum());
        tenantsForm.setPassword(userInfo.getPassword());

        Date date = userInfo.getStartTime();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = simpleDateFormat.format(date);
        tenantsForm.setStartTime(time);
        //Date类型转String类型
//        Date d = simpleDateFormat.parse(time);
        Date date1 = userInfo.getStopTime();
        String time1 = simpleDateFormat.format(date1);
        tenantsForm.setStopTime(time1);

        tenantsForm.setProperty(property);
        tenantsForm.setProjectNum(projectNum);
        return tenantsForm;
    }

}
